﻿using System;
using System.Threading.Tasks;
using Windows.Data.Xml.Dom;
using Windows.Storage;

namespace RssReader.Storage
{
    public class LocalStorage
    {
        private const string SyndicationFeedCategoriesFileName = "FeedCategories.xml";
        
        private StorageFile _storageFile;
        private StorageFolder _storageFolder;
        public async Task<XmlDocument> Read_categories_from_disk()
        {
            
            try
            {
                _storageFolder = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFolderAsync("Xml");
                _storageFile = await _storageFolder.GetFileAsync(SyndicationFeedCategoriesFileName);

                var loadSettings = new XmlLoadSettings
                                       {ProhibitDtd = false, ResolveExternals = false};
                return await XmlDocument.LoadFromFileAsync(_storageFile, loadSettings);
            }
            catch (Exception)
            {
                return null;
            }
        }
    }
}
